package com.qingbo.wu.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.qingbo.wu.oss.adapter.StorageAdapter;
import com.qingbo.wu.oss.adapter.impl.AliyunStorageAdapter;
import com.qingbo.wu.oss.adapter.impl.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: qingbo.wu
 * @Date: 2024/6/1 17:51
 * @Description:
 */
@Configuration
@RefreshScope
public class StorageConfig {


//    @NacosValue(value = "${storage.service.type}",autoRefreshed = true)
//    private String storageType;
    @Value(value = "${storage.service.type}")
    private String storageType;


    @Bean
    @RefreshScope
    public StorageAdapter getStorageService(){
        if ("minio".equals(storageType)){
            return new MinioStorageAdapter();
        }else if ("aliyun".equals(storageType)){
            return new AliyunStorageAdapter();
        }else {
            throw new IllegalArgumentException("没有找到对应的OSS存储器");
        }
    }
}
